package com.activitycode.activity.pet;

import java.util.List;

import com.activitycode.datamodel.model.DetailPetImages;
import com.activitycode.util.CommConstant;
import com.duostec.zhuyue.pets.R;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.display.RoundedBitmapDisplayer;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;


public class PetImageAdapter extends BaseAdapter{
	private List<DetailPetImages> list = null;
	private Context mContext;
	private ImageLoader imageLoader;
	private DisplayImageOptions options;
	private int width;
	private String flag;
	
	
	
	public PetImageAdapter(Context mContext, List<DetailPetImages> list,ImageLoader imageLoader,int width) {
		this.mContext = mContext;
		this.list = list;
		this.imageLoader = imageLoader;
		this.width = width;
		this.options = new DisplayImageOptions.Builder()		
		.cacheInMemory(true)
		.cacheOnDisc(true)
		.considerExifParams(true)
//		.displayer(new RoundedBitmapDisplayer(100))
		.build();
	}
	
	
	

	public int getCount() {
		return this.list.size();
	}

	public Object getItem(int position) {
		return list.get(position);
	}

	public long getItemId(int position) {
		return position;
	}

	public View getView(final int position, View view, ViewGroup arg2) {
		ViewHolder viewHolder = null;
		if (view == null) {
			viewHolder = new ViewHolder();
			view = LayoutInflater.from(mContext).inflate(R.layout.adapter_imageview, null);			
			viewHolder.head = (ImageView) view.findViewById(R.id.adapter_imageView_img);
			
			view.setTag(viewHolder);
		} else {
			viewHolder = (ViewHolder) view.getTag();
		}
		int w = (width-20)/3;
		viewHolder.head.getLayoutParams().height = w;
		if(list.get(position).getCutImg()!=null){
			if(list.get(position).getCutImg().equals("add")){
				
				viewHolder.head.setImageDrawable(mContext.getResources().getDrawable(R.drawable.pet_camera));
				
			}else{
				this.imageLoader.displayImage(CommConstant.SERVICE_HOST_IP_LAN_IMG+list.get(position).getCutImg(), viewHolder.head, options);
			}
			
        }
		return view;

	}
	


	final static class ViewHolder {

		ImageView head;
	}


	
}